
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ 界面调试
    local Widget = require "widgets/widget"
    local Image = require "widgets/image" -- 引入image控件
    local UIAnim = require "widgets/uianim"
    local Screen = require "widgets/screen"
    local AnimButton = require "widgets/animbutton"
    local ImageButton = require "widgets/imagebutton"
    local Menu = require "widgets/menu"
    local Text = require "widgets/text"
    local TEMPLATES = require "widgets/redux/templates"
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
local flg,error_code = pcall(function()
    print("WARNING:PCALL START +++++++++++++++++++++++++++++++++++++++++++++++++")
    local x,y,z =    ThePlayer.Transform:GetWorldPosition()  
    ----------------------------------------------------------------------------------------------------------------
        if ThePlayer.components.loramia_com_recharge then
            ThePlayer.components.loramia_com_recharge:DoDelta(100)
        end
    ----------------------------------------------------------------------------------------------------------------
    ---- 天赋调试
        -- if TheWorld.ismastersim then
        --     local loramia_com_talent_tree = ThePlayer.components.loramia_com_talent_tree

        --     -- loramia_com_talent_tree:AddPoint(10)

        --     loramia_com_talent_tree:Print()
        -- else
        --     local loramia_com_talent_tree = ThePlayer.replica.loramia_com_talent_tree


        --     -- loramia_com_talent_tree:Print()
        --     -- loramia_com_talent_tree:Unlock("abcc")
        -- end

        -- ThePlayer.replica.loramia_com_talent_tree:Unlock("energy_saving_mode")
        -- ThePlayer.components.loramia_com_talent_tree:Reset("energy_saving_mode")
    ----------------------------------------------------------------------------------------------------------------
    --- 技能环
        -- ThePlayer.___test_fn = function(inst)
        --     ------------------------------------------------------------------------------------------------------
        --     ---
        --         if TheInput == nil then
        --             return
        --         end
        --         local front_root = inst.HUD
        --         local atlas = "images/widgets/loramia_spell_ring.xml"
        --     ------------------------------------------------------------------------------------------------------
        --     --- 根节点创建
        --         if front_root.loramia_spell_ring_hud then   --- 杀掉重复的节点。重复点击则关闭界面
        --             front_root.loramia_spell_ring_hud:Kill()
        --             front_root.loramia_spell_ring_hud = nil
        --             return
        --         end
        --         local root = front_root:AddChild(Widget())
        --         front_root.loramia_spell_ring_hud = root

        --         function root:CloseSpellRing() -- 关闭技能圈圈
        --             self:Kill()
        --             front_root.loramia_spell_ring_hud = nil
        --         end
        --     ------------------------------------------------------------------------------------------------------
        --     --- 根节点参数
        --         -- root:SetHAnchor(0) -- 设置原点x坐标位置，0、1、2分别对应屏幕中、左、右
        --         -- root:SetVAnchor(0) -- 设置原点y坐标位置，0、1、2分别对应屏幕中、上、下
        --         root:SetHAnchor(1) -- 设置原点x坐标位置，0、1、2分别对应屏幕中、左、右
        --         root:SetVAnchor(2) -- 设置原点y坐标位置，0、1、2分别对应屏幕中、上、下
        --         root:SetScaleMode(SCALEMODE_FIXEDSCREEN_NONDYNAMIC)   --- 缩放模式
        --         local MainScale = 0.6
        --         local temp_scale = MainScale * 0.8
        --         local temp_scale_delta = 0.01
        --     ------------------------------------------------------------------------------------------------------
        --     --- 按钮盒子
        --         local button_box = root:AddChild(Widget())
        --         button_box:SetPosition(0,0,0)
        --         button_box:SetScale(MainScale,MainScale,MainScale)
        --     ------------------------------------------------------------------------------------------------------
        --     --- 透明度
        --         button_box:SetCanFadeAlpha(true)
        --         local max_alpha = 1
        --         local temp_alpha = 0.1
        --         local temp_alpha_delta = 0.02
        --         button_box:SetFadeAlpha(temp_alpha)
        --     ------------------------------------------------------------------------------------------------------
        --     --- 坐标跟随 角色中心修正
        --         local function root_position_update_fn()
        --             local s_pt_x,s_pt_y= TheSim:GetScreenPos(ThePlayer.Transform:GetWorldPosition()) -- 左下角为原点。
        --             -- print("player in screen",s_pt_x,s_pt_y)
        --             root:SetPosition(s_pt_x,s_pt_y+60,0)                    
        --             --- 缩放动画
        --             if temp_scale < MainScale then
        --                 temp_scale = math.clamp(temp_scale+temp_scale_delta,0.3,MainScale)
        --                 button_box:SetScale(temp_scale,temp_scale,temp_scale)
        --             end
        --             --- 透明度渐变
        --             if temp_alpha < max_alpha then
        --                 temp_alpha = math.clamp(temp_alpha+temp_alpha_delta,0,max_alpha)
        --                 button_box:SetFadeAlpha(temp_alpha)
        --             end
        --         end
        --         root_position_update_fn()
        --         TheInput:Loramia_Add_Update_Modify_Fn(root.inst,root_position_update_fn)
        --     ------------------------------------------------------------------------------------------------------
        --     --- 按钮创建API
        --         local function CreateButton(image,x,y,button_custom_fn,onclick_fn)
        --             image = image or "empty.tex"
        --             local temp_button = button_box:AddChild(ImageButton(
        --                 atlas,image,image,image,image,image
        --             ))
        --             if button_custom_fn then
        --                 button_custom_fn(temp_button)
        --             end
        --             temp_button:SetOnClick(function()                        
        --                 if onclick_fn then
        --                     onclick_fn(temp_button)
        --                 end
        --             end)
        --             temp_button:SetPosition(x,y)
        --             temp_button.black_mask = temp_button.image:AddChild(Image(atlas,"black.tex"))
        --             temp_button.black_mask:Hide()
        --             function temp_button:SetBlackMask(flag)
        --                 if flag then
        --                     self.black_mask:Show()
        --                 else
        --                     self.black_mask:Hide()
        --                 end
        --             end
        --             local button_scale = 128/150
        --             temp_button:SetScale(button_scale,button_scale,button_scale)
        --             return temp_button
        --         end
        --         local function CreateText(font,size,text,color)
        --             local temp_text = Text(font,size,text,color)
        --             function temp_text:CustomSetStr(str,x,y,ignore_regin)
        --                 self:SetString(str)
        --                 if not ignore_regin then
        --                     self:SetPosition(x + self:GetRegionSize()/2,y)
        --                 else
        --                     self:SetPosition(x,y)
        --                 end
        --             end
        --             return temp_text
        --         end
        --     ------------------------------------------------------------------------------------------------------
        --     --- 按钮组
        --         local base_x,base_y = 200,0
        --         local delta_x,delta_y = 60,100
        --         local txt_font = CODEFONT
        --         local txt_size = 80
        --         CreateButton(nil,base_x - delta_x,base_y + delta_y,function(temp_button)
        --             local spell_name = temp_button:AddChild(CreateText(txt_font,txt_size,"",{  255/255 , 255/255 ,255/255 , 1}))
        --             spell_name:CustomSetStr("宇宙之翼",90,0)
        --         end,function()
        --             --- 按钮点击
        --             print("BUTTON 1 ")
        --             root:CloseSpellRing()
        --         end)
        --         CreateButton(nil,base_x,base_y,function(temp_button)
        --             local spell_name = temp_button:AddChild(CreateText(txt_font,txt_size,"",{  255/255 , 255/255 ,255/255 , 1}))
        --             spell_name:CustomSetStr("创造物冲击",90,0)
        --         end,function()
        --             --- 按钮点击
        --             print("BUTTON 2 ")
        --             root:CloseSpellRing()
        --         end)
        --         CreateButton(nil,base_x - delta_x,base_y - delta_y,function(temp_button)
        --             local spell_name = temp_button:AddChild(CreateText(txt_font,txt_size,"",{  255/255 , 255/255 ,255/255 , 1}))
        --             spell_name:CustomSetStr("生命量产",90,0)
        --         end,function()
        --             --- 按钮点击
        --             print("BUTTON 3 ")
        --             root:CloseSpellRing()
        --         end)
        --         CreateButton(nil,80,-200,function(temp_button)
        --             -- temp_button.image:SetRotation(30)
        --             local spell_name = temp_button:AddChild(CreateText(txt_font,txt_size,"",{  255/255 , 255/255 ,255/255 , 1}))
        --             spell_name:CustomSetStr("节能模式",90,0)
        --         end,function()
        --             --- 按钮点击
        --             print("BUTTON 4 ")
        --             root:CloseSpellRing()
        --         end)
        --     ------------------------------------------------------------------------------------------------------
        --     --- 鼠标右键点击关闭UI
        --         root.temp_mouse_handler = TheInput:AddMouseButtonHandler(function(button, down, x, y) 
        --             if button == MOUSEBUTTON_RIGHT and down == false then
        --                 root.temp_mouse_handler:Remove()
        --                 root.temp_mouse_handler = nil
        --                 root:CloseSpellRing()
        --             end
        --         end)
        --         root.inst:ListenForEvent("onremove",function()
        --             if root.temp_mouse_handler then
        --                 root.temp_mouse_handler:Remove()
        --             end
        --         end)
        --     ------------------------------------------------------------------------------------------------------


        -- end
    ----------------------------------------------------------------------------------------------------------------
    --- 技能指示器
        -- ThePlayer.components.loramia_com_item_spell_controller:StartSpell("loramia_spell_excample_mouse_radius")

        -- if ThePlayer.test_fx then
        --     ThePlayer.test_fx:Remove()
        -- end
        -- local fx = SpawnPrefab("loramia_sfx_dotted_arrow_client")
        -- fx:PushEvent("Set",{
        --     pt = Vector3(x,y,z),
        -- })
        -- ThePlayer.test_fx = fx

        -- -- fx:SetRotation(45)

        -- local mouse_pt = TheInput:GetWorldPosition()
        -- local base_pt = Vector3(x,y,z)
        -- --- 计算角度。转换为 -180 ~ 180
        -- local angle = -math.deg(math.atan2(mouse_pt.z - base_pt.z,mouse_pt.x - base_pt.x))
        -- fx:SetRotation(angle)

    ----------------------------------------------------------------------------------------------------------------
    --- 技能控制器调试
        -- print( ThePlayer.replica.loramia_com_spell_controller:NetGetData("test_spell") )

        -- -- print( ThePlayer.components.loramia_com_spell_controller.classified.netvars["test_spell"]:value() )

        -- for k, v in pairs(ThePlayer.replica.loramia_com_spell_controller.classified.netvars) do
        --     print(k,v)
        -- end

        -- print( ThePlayer.components.loramia_com_spell_controller.classified )
    ----------------------------------------------------------------------------------------------------------------
    --- 
        -- ThePlayer.components.loramia_com_spell_controller:NetSetData("energy_saving_mode",false)

    ----------------------------------------------------------------------------------------------------------------
    --- 翅膀特效调试
        -- local inst = ThePlayer
        -- if inst.sfx_inst then
        --     inst.sfx_inst:Remove()
        -- end
        -- local sfx_inst = nil
        -- sfx_inst = SpawnPrefab("loramia_sfx_wings_of_universe")
        -- sfx_inst.entity:SetParent(inst.entity)
        -- sfx_inst.entity:AddFollower()
        -- sfx_inst.Follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0)
        -- sfx_inst.sfx = {}
        -- for i = 1, 6, 1 do
        --     local fx = SpawnPrefab("cane_victorian_fx")
        --     fx.entity:SetParent(sfx_inst.entity)
        --     fx.entity:AddFollower()
        --     fx.Follower:FollowSymbol(sfx_inst.GUID, "point_"..i,0,0,0)
        --     table.insert(sfx_inst.sfx,fx)
        -- end

        -- inst.sfx_inst = sfx_inst

        -- -- ThePlayer.replica.loramia_com_talent_tree:Unlock("wings_of_universe_ex")
    ----------------------------------------------------------------------------------------------------------------
    ---
        -- local MAX_DISTANCE = 12
        -- ThePlayer.____test_fn = function(owner,start_pt,end_pt)
        --     -----------------------------------------------------------------------------------------------
        --     --- 归一化方向
        --         local Normalize_Vect = (end_pt - start_pt):Normalize()
        --     -----------------------------------------------------------------------------------------------
        --     --- 以0.1为间隔，从 MAX_DISTANCE 回退到 0，寻找最远可通过点。 TheWorld.Map:IsPassableAtPoint(x,0,z)
        --         --- 为了减少计算量，从最远处开始，一旦发现不可通过点，则停止计算
        --         local max_distance = MAX_DISTANCE
        --         for i = max_distance,0,-0.1 do
        --             local pt = start_pt + Normalize_Vect * i
        --             if not TheWorld.Map:IsPassableAtPoint(pt.x,0,pt.z) then
        --                 max_distance = i
        --                 break
        --             end
        --         end
        --         local pt = start_pt + Normalize_Vect * max_distance                
        --     -----------------------------------------------------------------------------------------------
        --     ---
        --         owner.sg:GoToState("loramia_sg_spurt",{targetpos = pt})
        --     -----------------------------------------------------------------------------------------------
        --     --- 创建特效
        --         local BOUNCE_MUST_TAGS = { "_combat" }
        --         local BOUNCE_NO_TAGS = { "INLIMBO", "wall", "notarget", "player", "companion", "flight", "invisible", "noattack", "hiding" }
        --         local hit_targets = {}
        --         SpawnPrefab("loramia_spell_line_laser_beam"):PushEvent("Set",{
        --             start_pt = start_pt,
        --             end_pt = (pt - Normalize_Vect*1),
        --             colour = {100,100,0},
        --             delta_length = 0.8,
        --             delay_frame = 0.2,
        --             -- onhit_delay_frame = 10,
        --             onhitfn = function(x,y,z)                    
        --                 local ents = TheSim:FindEntities(x, 0, z, 1, BOUNCE_MUST_TAGS, BOUNCE_NO_TAGS)
        --                 for i,tempInst in ipairs(ents) do
        --                     if tempInst and tempInst:IsValid() and not hit_targets[tempInst] 
        --                         and tempInst.components.combat
        --                     then
        --                         hit_targets[tempInst] = true
        --                         tempInst.components.combat:GetAttacked(owner,30)
        --                     end
        --                 end
        --             end,
        --         })
        --     -----------------------------------------------------------------------------------------------

        -- end
    ----------------------------------------------------------------------------------------------------------------
    ---

        -- SpawnPrefab("loramia_spell_line_laser_beam"):PushEvent("Set",{
        --     start_pt = Vector3(x,y,z),
        --     end_pt = Vector3(x+10,y,z+15),
        --     colour = {255,255,0},
        --     delta_length = 1,
        --     delay_frame = 0.4,
        --     -- onhit_delay_frame = 10,
        --     -- onhit = function(x,y,z)

        --     -- end,
        -- })
    ----------------------------------------------------------------------------------------------------------------
    ---
        -- ThePlayer.components.loramia_com_recharge:DoDelta(10)

        -- ThePlayer.components.loramia_com_talent_tree:Reset()

        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("creation_impact")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("creation_synchronization")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("life_mass_production")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("evolution_sharpness")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("mechanical_liberation")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("evolution_rapid_strike")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("evolution_armored_rapid_strike")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("evolution_analysis")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("capacity_expansion_I")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("capacity_expansion_II")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("capacity_expansion_III")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("capacity_expansion_IV")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("evolution_holiness")
        -- ThePlayer.components.loramia_com_talent_tree:ForceUnlock("evolution_subtlety")
    ----------------------------------------------------------------------------------------------------------------
    --- 电器
        -- local ents = TheSim:FindEntities(x, 0, z, 4, {"loramia_com_power_device"})
        -- local device = ents[1]
        -- for k, v in pairs(device.components.loramia_com_power_device:GetAllLinkedBatteries()) do
        --     print(k,v)
        -- end
    ----------------------------------------------------------------------------------------------------------------
    --- 暗影傀儡
        -- local worker_prefab = {"shadowlumber","shadowminer","shadowdigger"}
        -- -- ThePlayer.components.petleash:SpawnPetAt(x+5, 0,z, "shadowlumber")
        -- -- ThePlayer.components.petleash:SpawnPetAt(x+5, 0,z, "shadowminer")
        -- -- ThePlayer.components.petleash:SpawnPetAt(x+5, 0,z, "shadowdigger")
        -- for k, v in pairs(worker_prefab) do
        --     local pet = ThePlayer.components.petleash:SpawnPetAt(x+5, 0,z, v)
        --     print(pet)
        -- end


    ----------------------------------------------------------------------------------------------------------------
    --- 调试发电机
        -- local ents = TheSim:FindEntities(x, 0, z, 10,{"loramia_building_sharpstrike_creation"})
        -- local inst = ents[1]

        -- inst.components.loramia_com_power_battery:SetCurrent(100)

        -- ThePlayer.test_speed = 0.01
    ----------------------------------------------------------------------------------------------------------------
    ---
        --  ThePlayer.__test_fn = function(inst,front_root)
        --     -----------------------------------------------------------------
        --     --
        --         local root = front_root:AddChild(Widget())
        --         root:SetHAnchor(1) -- 设置原点x坐标位置，0、1、2分别对应屏幕中、左、右
        --         root:SetVAnchor(2) -- 设置原点y坐标位置，0、1、2分别对应屏幕中、上、下
        --         root:SetPosition(1000,500)
        --         root:SetScaleMode(SCALEMODE_FIXEDSCREEN_NONDYNAMIC)   --- 缩放模式
        --     -----------------------------------------------------------------
        --     ---
        --         local leave_button = root:AddChild(ImageButton("images/global_redux.xml",
        --             "button_carny_xlong_hover.tex",
        --             "button_carny_xlong_hover.tex",
        --             "button_carny_xlong_hover.tex",
        --             "button_carny_xlong_hover.tex",
        --             "button_carny_xlong_hover.tex"
        --         ))
        --         leave_button:SetOnClick(function()
        --             inst.replica.loramia_com_tent:PlayerCommandWakeUp(ThePlayer)
        --         end)
        --         local scale = 0.3
        --         leave_button:SetScale(scale,scale,scale)
        --     -----------------------------------------------------------------
        --     ---
        --         local s_pt_x,s_pt_y= TheSim:GetScreenPos(inst.Transform:GetWorldPosition()) -- 左下角为原点。
        --         local offset_x,offset_y = 0,200
        --         root:SetPosition(s_pt_x + offset_x,s_pt_y + offset_y)
        --     -----------------------------------------------------------------
        --     ---
        --         return root            
        --     -----------------------------------------------------------------
        --  end
    ----------------------------------------------------------------------------------------------------------------
    --- 寻宝界面调试
        -- -----------------------------------------------------------------
        -- ---
        --     local front_root = ThePlayer.HUD
        -- -----------------------------------------------------------------
        -- ---
        --     local root = front_root:AddChild(Widget())
        --     root:SetHAnchor(ANCHOR_MIDDLE)
        --     root:SetVAnchor(ANCHOR_MIDDLE)
        --     root:SetScaleMode(SCALEMODE_FIXEDSCREEN_NONDYNAMIC)
        --     root:MoveToBack()
        -- -----------------------------------------------------------------
        -- --- test
        --     if front_root.__test_hud then
        --         front_root.__test_hud:Kill()
        --         front_root.__test_hud = nil
        --         root:Kill()
        --         return
        --     end
        --     front_root.__test_hud = root
        --     -- root.inst:ListenForEvent("close",function()
        --     --     root.mask:GetAnimState():PlayAnimation("over_pre")
        --     -- end)
        --     local old_root_Kill = root.Kill
        --     root.Kill = function(self)
        --         root.mask:GetAnimState():PlayAnimation("over_pst")
        --         TheFrontEnd:GetSound():PlaySound("meta4/wires_minigame/inspectacles/overlay_deactivate")
        --         root.mask.inst:ListenForEvent("animover",function()
        --             old_root_Kill(self)
        --             print("root killed")
        --         end)
        --     end
        -- -----------------------------------------------------------------
        -- ---
        --     local bg = root:AddChild(Widget())
        --     bg:SetClickable(false)
        -- -----------------------------------------------------------------
        -- ---
        --     local mask = bg:AddChild(UIAnim())
        --     root.mask = mask
        --     mask:GetAnimState():SetBank("inspectacles_over")
        --     mask:GetAnimState():SetBuild("inspectacles_over")
        --     mask:GetAnimState():PlayAnimation("over_pre")
        --     mask:GetAnimState():PushAnimation("over_idle",true)
        --     TheFrontEnd:GetSound():PlaySound("meta4/wires_minigame/inspectacles/overlay_activate")

        -- -----------------------------------------------------------------
        -- ---
        --     local pinger = bg:AddChild(UIAnim())
        --     pinger:SetHAnchor(ANCHOR_LEFT)
        --     pinger:SetVAnchor(ANCHOR_BOTTOM)
        --     pinger:GetAnimState():SetBank("winona_inspectacles_fx")
        --     pinger:GetAnimState():SetBuild("winona_inspectacles_fx")
        --     pinger:GetAnimState():AnimateWhilePaused(false)
        --     pinger:GetAnimState():PlayAnimation("radar",true)
        --     pinger:Hide()
        -- -----------------------------------------------------------------
        -- --- 测试pinger
        --     pinger.inst:DoPeriodicTask(0.3,function()
        --         local target = TheSim:FindFirstEntityWithTag("multiplayer_portal")
        --         -- print("target",target)
        --         if target == nil then
        --             pinger:Hide()
        --             return
        --         end
        --         local player = ThePlayer
        --         local tx,ty,tz = target.Transform:GetWorldPosition()
        --         local px,py,pz = player.Transform:GetWorldPosition()

        --         local x, y, angle = GetIndicatorLocationAndAngle(player, tx, tz, 0, 0, false)
        --         local sw, sh = TheSim:GetScreenSize()
        --         local angletocenter = math.atan2(y - sh * .5, x - sw * .5)
        --         local scale = pinger:GetScale()
        --         local r = 150
        --         x, y = x + r * math.cos(angletocenter) * scale.x, y + r * math.sin(angletocenter) * scale.y
        --         pinger:SetRotation(angle - 45)
        --         pinger:SetPosition(x, y)
        --         pinger:Show()
        --     end)
        -- -----------------------------------------------------------------
    ----------------------------------------------------------------------------------------------------------------
    --- 
        -- ThePlayer.___hud_install = function(inst,root)
        --     local deep_search_btn = root:AddChild(ImageButton("images/widgets/loramia_spell_ring.xml","empty.tex","empty.tex","empty.tex","empty.tex","empty.tex"))
        --     deep_search_btn:SetScale(.7,.7)
        --     deep_search_btn:SetPosition(200,200)
        --     deep_search_btn.inst:ListenForEvent("close",function()
        --         deep_search_btn:Hide()
        --     end,root.inst)
        --     deep_search_btn:SetOnClick(function()
        --         print("666666666 click")
        --     end)
        -- end
        -- local inst = TheSim:FindFirstEntityWithTag("loramia_building_inspectaclesbox")
        -- -- print(inst)
        -- print(inst.Transform:GetWorldPosition())
        -- -- inst.AnimState:SetErosionParams(0.1,-0.1,-1)
        -- -- inst.AnimState:SetErosionParams(0.1,-5,-1)
        -- -- marker.AnimState:SetErosionParams(0,0,0)
        -- -- marker.AnimState:SetBuild("loramia_building_inspectaclesbox")
        -- ThePlayer.Transform:SetPosition(inst.Transform:GetWorldPosition())
        -- -- inst.AnimState:SetBank("inspectaclesbox")
        -- -- inst.AnimState:SetBuild("inspectaclesbox")
        -- -- inst.AnimState:PlayAnimation("idle_fixed_loop",true)

        -- -- ThePlayer.AnimState:SetClientSideBuildOverrideFlag("loramia_building_inspectaclesbox_searching", true)


        -- local item = TheSim:FindFirstEntityWithTag("loramia_com_inspectacle_searcher")
        -- print(item)
        -- print(item.replica.loramia_com_inspectacle_searcher:GetPingerTarget())

        -- if ThePlayer.components.inspectaclesparticipant == nil then
        --     ThePlayer:AddComponent("inspectaclesparticipant")
        -- end
        -- -- ThePlayer.components.inspectaclesparticipant:OnSignalPulse()



     
    ----------------------------------------------------------------------------------------------------------------
    ----- 拼图小游戏
        -- ----------------------------------------------------
        -- ---
        --     if ThePlayer.__test_root and ThePlayer.__test_root.inst:IsValid() then
        --         ThePlayer.__test_root:Kill()
        --     end
        -- ----------------------------------------------------
        -- --- 前置根节点、素材库
        --     local front_root = ThePlayer.HUD:AddChild(Widget())
        --     local atlas = "images/widgets/loramia_inspectaclesbox_game.xml"
        --     front_root:SetHAnchor(0) -- 设置原点x坐标位置，0、1、2分别对应屏幕中、左、右
        --     front_root:SetVAnchor(0) -- 设置原点y坐标位置，0、1、2分别对应屏幕中、上、下
        --     front_root:SetPosition(0,0)
        --     front_root:SetScaleMode(SCALEMODE_FIXEDSCREEN_NONDYNAMIC)   --- 缩放模式
        -- ----------------------------------------------------
        -- --- 根节点
        --     local root = front_root:AddChild(Widget())
        --     local scale = 0.6
        --     root:SetScale(scale,scale,scale)
        -- ----------------------------------------------------
        -- ---
        --     local bg = root:AddChild(Image(atlas,"background.tex"))
        -- ----------------------------------------------------
        -- --- 关闭按钮
        --     local button_close = bg:AddChild(ImageButton(atlas,"button_active.tex","button_active.tex","button_active.tex","button_active.tex","button_active.tex"))
        --     button_close:SetPosition(630,370)
        --     button_close:SetOnClick(function()
        --         front_root:Kill()
        --     end)
        --     button_close.image:AddChild(Image(atlas,"icon_close.tex"))
        --     root.button_close = button_close
        -- ----------------------------------------------------
        -- --- 刷新按钮
        --     local button_refresh = bg:AddChild(ImageButton(atlas,"button_active.tex","button_active.tex","button_active.tex","button_active.tex","button_active.tex"))
        --     button_refresh:SetPosition(440,-380)
        --     button_refresh:SetOnClick(function()
        --         print("refresh")
        --     end)
        --     button_refresh.image:AddChild(Image(atlas,"icon_refresh.tex"))
        --     root.button_refresh = button_refresh
        -- ----------------------------------------------------
        -- --- 星星按钮
        --     local button_star = bg:AddChild(ImageButton(atlas,"button_active.tex","button_active.tex","button_active.tex","button_active.tex","button_active.tex"))
        --     button_star:SetPosition(570,-380)
        --     button_star:SetOnClick(function()
        --         print("star")
        --     end)
        --     local star_icon = button_star.image:AddChild(Image(atlas,"icon_star.tex"))
        --     root.button_star = button_star
        --     button_star.img_show = true
        --     function button_star:SetActive(flag)
        --         if flag then
        --             self:SetTextures(atlas,"button_active.tex","button_active.tex","button_active.tex","button_active.tex","button_active.tex")
        --             self:SetClickable(true)
        --             if self.aciving_task then
        --                 self.aciving_task:Cancel()
        --             end
        --             self.aciving_task = self.inst:DoPeriodicTask(0.3,function()
        --                 if self.img_show then
        --                     star_icon:Show()
        --                 else
        --                     star_icon:Hide()
        --                 end
        --                 self.img_show = not self.img_show
        --             end)
        --         else
        --             self:SetTextures(atlas,"button_deacitve.tex","button_deacitve.tex","button_deacitve.tex","button_deacitve.tex","button_deacitve.tex")
        --             self:SetClickable(false)
        --             if self.aciving_task then
        --                 self.aciving_task:Cancel()
        --                 self.aciving_task = nil
        --             end
        --         end
        --     end
        --     button_star:SetActive(false)
        -- ----------------------------------------------------
        -- --- box
        --     local box = bg:AddChild(Image(atlas,"box_frame.tex"))
        --     box:SetScale(1.2,1.2,1.2)
        -- ----------------------------------------------------
        -- --- 基于XY的坐标系。 X-9 .Y-5
        --     local SLOTS_MAX_X = 9
        --     local SLOTS_MAX_Y = 5
        --     local slots_pos = {}
        --     local all_pos = {}
        --     local start_x,start_y = -400,200
        --     for y = 1, SLOTS_MAX_Y, 1 do
        --         for x = 1, SLOTS_MAX_X, 1 do
        --             slots_pos[y] = slots_pos[y] or {}
        --                 slots_pos[y][x] = Vector3(start_x + (x-1)*100,start_y - (y-1)*100,0)
        --                 table.insert(all_pos,slots_pos[y][x])
        --         end
        --     end
        --     -- print("pos",#all_pos)
        -- ----------------------------------------------------
        -- --- 
        --     local mini_game_atlas = "images/widgets/loramia_inspectaclesbox_game_tex_"..math.random(12)..".xml"
        --     local function create_slot(num)                
        --         -- local temp_slot = box:AddChild(Image(mini_game_atlas,num..".tex"))
        --         local image_name = tostring(num)..".tex"
        --         local temp_slot = box:AddChild(ImageButton(mini_game_atlas,image_name,image_name,image_name,image_name,image_name))
        --         temp_slot.focus_scale = {1,1,1}
        --         local slot_scale = 1.015
        --         temp_slot:SetScale(slot_scale,slot_scale,slot_scale)
        --         temp_slot.num = num
        --         if TUNING.LORAMIA_DEBUGGING_MODE then
        --             temp_slot.image:AddChild(Text(CODEFONT,40,tostring(num),{0/255,255/255,0/255,1}))
        --         end
        --         function temp_slot:GetSlottXY()
        --             return self.s_x,self.s_y
        --         end
        --         function temp_slot:SetSlotXY(s_x,s_y)
        --             self.s_x = s_x
        --             self.s_y = s_y
        --             self:SetPosition(slots_pos[s_y][s_x])
        --         end
        --         temp_slot:SetOnClick(function()
        --             -- print("click",temp_slot.num)
        --             box.inst:PushEvent("slot_click",temp_slot)
        --         end)
        --         return temp_slot
        --     end
        -- ----------------------------------------------------
        -- --- 获取不重复的数字 1-44
        --     local spawned_list = {}
        --     for i = 1, 44, 1 do
        --         table.insert(spawned_list,i)
        --     end
        --     local function get_random_slot_png_num()
        --         local index = math.random(#spawned_list)
        --         local num = spawned_list[index]
        --         table.remove(spawned_list,index)
        --         return num
        --     end
        -- ----------------------------------------------------
        -- ---
        --     local slots = {}
        --     local temp_num = 1
        --     for SY = 1,SLOTS_MAX_Y,1 do
        --         slots[SY] = slots[SY] or {}
        --         for SX = 1,SLOTS_MAX_X,1 do
        --             if temp_num <= 44 then
        --                 local temp_slot = create_slot(get_random_slot_png_num())
        --                 temp_slot:SetSlotXY(SX,SY)
        --                 slots[SY][SX] = temp_slot
        --             end
        --             temp_num = temp_num + 1
        --         end
        --     end
        -- ----------------------------------------------------
        -- --- 转换逻辑
        --     local function findEmptySlot(slots, s_x, s_y, maxDistance)
        --         local directions = {
        --             {dx = -1, dy = 0}, -- left
        --             {dx = 1, dy = 0},  -- right
        --             {dx = 0, dy = -1}, -- up
        --             {dx = 0, dy = 1},  -- down
        --             {dx = -1, dy = -1},-- left-up
        --             {dx = 1, dy = -1}, -- right-up
        --             {dx = -1, dy = 1},-- left-down
        --             {dx = 1, dy = 1}  -- right-down
        --         }
            
        --         for distance = 1, maxDistance do
        --             for _, dir in ipairs(directions) do
        --                 local check_x = s_x + dir.dx * distance
        --                 local check_y = s_y + dir.dy * distance
            
        --                 if check_x >= 1 and check_x <= SLOTS_MAX_X and check_y >= 1 and check_y <= SLOTS_MAX_Y then
        --                     local slot = slots[check_y][check_x]
        --                     if not slot then
        --                         return check_x, check_y
        --                     end
        --                 end
        --             end
        --         end
        --     end
            
        --     box.inst:ListenForEvent("slot_click", function(_, selected_slot)
        --         local s_x, s_y = selected_slot:GetSlottXY()
        --         local ret_slot_x, ret_slot_y = findEmptySlot(slots, s_x, s_y, 9) -- 支持最多5格距离
            
        --         if ret_slot_x and ret_slot_y then
        --             slots[s_y][s_x] = nil
        --             slots[ret_slot_y][ret_slot_x] = selected_slot
        --             selected_slot:SetSlotXY(ret_slot_x, ret_slot_y)
        --             box.inst:PushEvent("check_succeed")
        --         end
        --     end)
        -- ----------------------------------------------------
        -- --- 检查通过
        --     local function check_succeed()
        --         local temp_num = 1
        --         for SY = 1,SLOTS_MAX_Y,1 do
        --             for SX = 1,SLOTS_MAX_X,1 do
        --                 if temp_num <= 44 then
        --                     local temp_slot = slots[SY][SX]
        --                     if temp_slot == nil or temp_slot.num ~= temp_num then
        --                         return false
        --                     end
        --                 end
        --                 temp_num = temp_num + 1
        --             end
        --         end
        --         return true
        --     end
        --     box.inst:ListenForEvent("check_succeed",function()
        --         if check_succeed() then
        --             button_star:SetActive(true)
        --         else
        --             button_star:SetActive(false)
        --         end
        --     end)
        -- ----------------------------------------------------
        -- ---
        --     ThePlayer.__test_root = front_root
        -- ----------------------------------------------------
    ----------------------------------------------------------------------------------------------------------------
    --- 
        if ThePlayer.components.loramia_com_talent_tree then
            ThePlayer.components.loramia_com_talent_tree:AddPointsByMaxCheck(100)
        end
    ----------------------------------------------------------------------------------------------------------------
    --- 
        -- local inst = TheSim:FindFirstEntityWithTag("loramia_building_multi_armed_creation")
      
        -- local function slot_display(inst,slot_index,temp_item)
        --     slot_index = math.clamp(slot_index,1,10)

        --     local tar_atlas = nil
        --     local tar_image = nil
        --     local imagename = temp_item.nameoverride or temp_item.components.inventoryitem.imagename or temp_item.prefab
        --     imagename  = string.gsub(imagename,".tex", "") .. ".tex"
        --     local atlasname = temp_item.components.inventoryitem.atlasname or GetInventoryItemAtlas(imagename)
        --     if TheSim:AtlasContains(atlasname, imagename) then
        --         --- 官方物品
        --         tar_atlas = atlasname
        --         tar_image = imagename
        --         -- break
        --     else
        --         --- 自定义MOD物品
        --         atlasname = GetInventoryItemAtlas(imagename)
        --         atlasname = resolvefilepath_soft(atlasname) --为了兼容mod物品，不然是没有这道工序的
        --         tar_atlas = atlasname
        --         tar_image = imagename
        --         -- break
        --     end
        --     if tar_atlas and tar_image and TheSim:AtlasContains(tar_atlas, tar_image) then
        --         -- break
        --     else
        --         tar_atlas = nil
        --         tar_image = nil
        --     end

        --     if tar_image and tar_atlas then
        --         inst.AnimState:OverrideSymbol("slot_"..slot_index,tar_atlas,tar_image)
        --     else
        --         inst.AnimState:OverrideSymbol("slot_"..slot_index,"loramia_building_multi_armed_creation","empty")
        --     end
        -- end

        -- local item_prefab = {
        --     "transistor","cutstone","marblebean","thulecite","palmcone_scale","goldnugget","rocks","lightbulb","nightmarefuel","horrorfuel"
        -- }

        -- for k, prefab in pairs(item_prefab) do
        --     local item = SpawnPrefab(prefab)
        --     item.Transform:SetPosition(x,y,z)
        --     slot_display(inst,k,item)
        --     item:Remove()
        -- end
    ----------------------------------------------------------------------------------------------------------------
    ---        
    ----------------------------------------------------------------------------------------------------------------
    print("WARNING:PCALL END   +++++++++++++++++++++++++++++++++++++++++++++++++")
end)

if flg == false then
    print("Error : ",error_code)
end

-- dofile(resolvefilepath("test_fn/test.lua"))